package org.zyj.io.example.case9;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

class CustomDecoder extends ReplayingDecoder<Void> {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        var length = in.readInt();
        byte[] content = new byte[length];
        in.readBytes(content);
        var customProtocol = new CustomProtocol(length, content);
        out.add(customProtocol);
    }
}
